{% extends "swarming/base.html" %}


{% block headers %}
<style>
  h1 {
    margin-top: 10px;
    margin-bottom: 10px;
  }

  table.property_table {
    font-family: monospace;
    border-spacing: 0;
  }

  table.property_table tbody tr:nth-child(even) {
    background-color: #eeeeee;
  }

  table.property_table td {
    padding-left: 1em;
    padding-right: 1em;
  }

  table.property_table tbody tr:hover {
    background-color: #eeffee;
  }

  .bot_bad_version {
    background-color: #ffffee;
  }

  .bot_dead {
    background-color: #ffdddd !important;
  }

  .bot_quarantined {
    background-color: #ff0303 !important;
  }
</style>

<script>
  function submit_form() {
    document.getElementById("order").submit();
  }
</script>
{% endblock %}


{% block body %}
{% import 'swarming/bot_view.html' as bot_view %}

<h1>Known bots</h1>
<a href="/">Back to root</a>
<p>
<table class=property_table>
  <tbody>
    <tr>
      <td>Current bot version</td>
      <td>{{current_version[:8]}}</td>
    </tr>
    <tr>
      <td>Number of bots alive</td>
      <td>{{num_bots_alive}}</td>
    </tr>
    <tr>
      <td>Number of busy bots</td>
      <td>{{num_bots_busy}}</td>
    </tr>
    <tr>
      <td>Number of bots dead</td>
      <td>{{num_bots_dead}}</td>
    </tr>
    <tr>
      <td>Number of bots quarantined</td>
      <td>{{num_bots_quarantined}}</td>
    </tr>
  </tbody>
</table>
<p>

<form id="order" name="order" method="GET">
  {% for sort_option in sort_options %}
    <label>
      <input type="radio" name="sort_by" value="{{sort_option.key}}"
          onchange="submit_form()"
          {% if sort_by == sort_option.key %}checked{%endif%}>
        {{sort_option.name}}
      </input>
    </label>
  {% endfor %}
</form>
<p>

{% import 'swarming/bot_view.html' as bot_view %}
<table id="machine-table" class="alterning_background"
    summary="This table lists all machines that have polled this server">
  <thead>
    <th>ID</th>
    <th>Last contact</th>
    <th>Dimensions</th>
    <th>State</th>
    <th>Version</th>
    <th>Task</th>
  </thead>
  <tbody>
    {% for bot in bots %}
    <tr class="request {% if bot.is_dead(now) %}bot_dead{% elif bot.quarantined %}bot_quarantined{% endif %}">
        <td nowrap>{{bot_view.bot_link(bot.id, is_privileged_user)}}</td>
        <td>
          {{(now-bot.last_seen_ts)|timedeltaformat}}
          {% if is_admin and bot.is_dead(now) %}
            <form id="delete_{{bot.id}}" method="post"
                action="/restricted/bot/{{bot.id}}/delete">
              <input type="hidden" name="xsrf_token" value="{{xsrf_token}}" />
              <input type="submit" value="Delete" />
            </form>
          {% endif %}
        </td>
        <td nowrap>{{bot_view.render_dict(bot.dimensions)}}</td>
        <td nowrap>{{bot_view.render_dict(bot.state)}}</td>
        <td {%if bot.version != current_version%}class="bot_bad_version"{%endif%}>
          {{bot.version[:8]}}
        </td>
        <td>
          {% if bot.task %}
          <a href="/user/task/{{bot.task_id}}">{{bot.task_name}}</a>
          {% else %}&#8209;&#8209;{% endif%}
        </td>
      </tr>
    {% endfor %}
  </tbody>
</table>

{% if cursor %}
<p>
<a href="/restricted/bots?limit={{limit}}&sort_by={{sort_by}}&cursor={{cursor}}">Next page</a>
{% endif %}

{% endblock %}
